{extend name='main'}

{block name="button"}
<!--{if auth("start") && $iswin}-->
<button data-load='{:url("start")}' class='layui-btn layui-btn-sm layui-btn-primary'>开始监听</button>
<!--{/if}-->
<!--{if auth("stop") && $iswin}-->
<button data-load='{:url("stop")}' data-confirm="确定要停止主进程监听吗？" class='layui-btn layui-btn-sm layui-btn-primary'>停止监听</button>
<!--{/if}-->
<!--{if auth("remove")}-->
<button data-action='{:url("remove")}' data-rule="id#{key}" data-confirm="确定批量删除任务吗？" class='layui-btn layui-btn-sm layui-btn-primary'>批量删除</button>
<!--{/if}-->
<!--{if auth("clear")}-->
<button data-load='{:url("clear")}' data-confirm="确定要创建定时清理任务吗？" class='layui-btn layui-btn-sm layui-btn-primary'>定时清理</button>
<!--{/if}-->
{/block}

{block name="content"}

<div class="think-box-shadow table-block">
    <div class="layui-row layui-col-space20 portal-block-container notselect">
        <div class="layui-col-sm6 layui-col-md6 layui-col-lg3">
            <div class="portal-block-item nowrap" style="background:linear-gradient(-125deg,#57bdbf,#2f9de2)">
                <div>待处理</div>
                <div>{$total.pre|default=0}</div>
                <div>待处理的任务数量</div>
            </div>
            <i class="portal-block-icon layui-icon layui-icon-star"></i>
        </div>
        <div class="layui-col-sm6 layui-col-md6 layui-col-lg3">
            <div class="portal-block-item nowrap" style="background:linear-gradient(-125deg,#ff7d7d,#fb2c95)">
                <div>处理中</div>
                <div>{$total.dos|default=0}</div>
                <div>处理中的任务数量</div>
            </div>
            <i class="portal-block-icon layui-icon layui-icon-log"></i>
        </div>
        <div class="layui-col-sm6 layui-col-md6 layui-col-lg3">
            <div class="portal-block-item nowrap" style="background:linear-gradient(-113deg,#c543d8,#925cc3)">
                <div>处理完成</div>
                <div>{$total.oks|default=0}</div>
                <div>处理完成的任务数量</div>
            </div>
            <i class="portal-block-icon layui-icon layui-icon-release"></i>
        </div>
        <div class="layui-col-sm6 layui-col-md6 layui-col-lg3">
            <div class="portal-block-item nowrap" style="background:linear-gradient(-141deg,#ecca1b,#f39526)">
                <div>处理失败</div>
                <div>{$total.ers|default=0}</div>
                <div>处理失败的任务数量</div>
            </div>
            <i class="portal-block-icon layui-icon layui-icon-engine"></i>
        </div>
    </div>

    {include file='queue/index_search'}
    <table class="layui-table margin-top-15" lay-skin="line">
        {notempty name='list'}
        <thead>
        <tr>
            <th class='list-table-check-td think-checkbox'>
                <label><input data-auto-none data-check-target='.list-check-box' type='checkbox'></label>
            </th>
            <th class='text-left nowrap'>任务信息</th>
            <th class='text-left nowrap'>任务时间</th>
            <th class='text-left nowrap'>任务状态</th>
        </tr>
        </thead>
        {/notempty}
        <tbody>
        {foreach $list as $key=>$vo}
        <tr>
            <td class='list-table-check-td think-checkbox'>
                <label><input class="list-check-box" value='{$vo.id}' type='checkbox'></label>
            </td>
            <td class='text-left nowrap'>
                任务编号：{$vo.code|default=''}<br>
                任务名称：{$vo.title|default=''}<br>
                任务指令：{$vo.command|default=''}
            </td>
            <td class='text-left nowrap'>
                计划时间：{$vo.exec_time|format_datetime} {if isset($vo.exec_pid) and $vo.exec_pid>0}（ 进程 <b class="color-blue">{$vo.exec_pid|default='-'}</b> ）{/if}<br>
                {if $vo.enter_time>0 and $vo.outer_time>0} 执行时间：{$vo.enter_time|format_datetime}（ 耗时 <b class="color-blue">{:sprintf("%.4f",$vo.outer_time-$vo.enter_time)}</b> 秒 ）{elseif $vo.status eq 2} 执行时间：{$vo.enter_time|format_datetime}（ 任务执行中 ）{else}执行时间：<span class="color-desc">任务还没有执行，等待执行...</span>{/if}<br>
                创建时间：{$vo.create_at|format_datetime} {if isset($vo.loops_time) and $vo.loops_time > 0}（ 每 <b class="color-blue">{$vo.loops_time|default='0'}</b> 秒执行，共 <b class="color-blue">{$vo.attempts}</b> 次）{else}（ 共执行 <b class="color-blue">{$vo.attempts}</b> 次 ） {/if}
            </td>
            <td class='text-left nowrap'>
                <div class="margin-bottom-5">
                    {if isset($vo.loops_time) and $vo.loops_time > 0}
                    <span class="layui-badge layui-bg-orange margin-right-5">循</span>
                    {/if}

                    {if $vo.rscript eq 1}
                    <span class="layui-badge layui-bg-green margin-right-5">复</span>
                    {else}
                    <span class="layui-badge layui-bg-blue margin-right-5">单</span>
                    {/if}

                    {eq name='vo.status' value='1'}
                    <span class="layui-badge layui-bg-black">等待处理</span>
                    {elseif $vo.status eq 2}
                    <span class="layui-badge layui-bg-green">正在处理</span>
                    {elseif $vo.status eq 3}
                    <span class="layui-badge layui-bg-blue">处理完成</span>
                    {elseif $vo.status eq 4 and auth('redo')}
                    <span class="layui-badge layui-bg-red margin-right-5">处理失败</span>
                    <a class="layui-badge layui-bg-green" data-confirm="确定要重置该任务吗？" data-tips-text="重置该任务" data-queue="{:url('redo')}?code={$vo.code}"><i class="layui-icon font-s12">&#xe669;</i></a>
                    {/eq}
                    {if auth("remove") }
                    <a data-action='{:url("remove")}' data-confirm="确定要删除该任务吗？" data-value="id#{$vo.id}" data-tips-text="删除该任务" class='layui-badge layui-bg-red margin-left-5'><i class="layui-icon">&#xe640;</i></a>
                    {/if}
                    <a onclick="$.loadQueue('{$vo.code}',false)" data-tips-text="任务进度信息" class='layui-badge layui-bg-orange margin-left-5'><i class="layui-icon">&#xe705;</i></a>
                </div>
                <div class="color-desc">{$vo.exec_desc|raw|default="没有获取到状态描述"}</div>
            </td>
        </tr>
        {/foreach}
        </tbody>
    </table>

    {empty name='list'}<span class="notdata">没有记录哦</span>{else}{$pagehtml|raw|default=''}{/empty}

</div>
{/block}